package com.xxx.config;

import com.xxx.config.exception.support.DefaultExceptionMapperSupport;
import com.xxx.config.exception.support.JsonMapperExceptionSupport;
import com.xxx.config.exception.support.UncaughtExceptionMapperSupport;
import com.xxx.config.exception.support.ValidationExceptionMapperSupport;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider;
import org.glassfish.jersey.logging.LoggingFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.context.annotation.Configuration;

/**
 * Jersey配置类
 */
@Configuration
public class JerseyConfig extends ResourceConfig {

    public JerseyConfig() {
        // 开启日志
        register(LoggingFeature.class);
        // 注册文件上传
        register(MultiPartFeature.class);
        // 注册跨域处理
        register(CorsFilter.class);
        // 注册自定义拦截器实现
        register(RequestFilter.class);
        // 注册json序列化
        register(JacksonJsonProvider.class);
        // 注册异常类资源
        register(DefaultExceptionMapperSupport.class);
        register(JsonMapperExceptionSupport.class);
        register(UncaughtExceptionMapperSupport.class);
        register(ValidationExceptionMapperSupport.class);

        // 注册包扫描 这个方法在开发使用没问题，但是打包jar后，找不到 class 文件
        packages("com.xxx.api");

        // 定义扫描包含接口资源包
//        registerClasses(ClassUtil.findAllClasses("com.xxx.api"));
    }
}
